<?php
class View_Admin_Message extends View_Admin_Index_Template {
    public $oTemp;
    public function displayMessageInbox($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/message_board_inbox.html');
        $this->oTemp->assign('pageHeding', 'Inbox');

        $this->oTemp->assign_file('temp_filter', PATH_TEMPLATE_ADMIN .'html/message_filter_calendar.html');
        $this->oTemp->assign_file('temp_message_js', PATH_TEMPLATE_ADMIN .'html/message_board_js.html');
        $this->oTemp->assign_file('temp_poup', PATH_TEMPLATE_ADMIN .'html/message_board_popup.html');

        $this->displayCalendarDefault($oModel);
        $this->oTemp->assign('value','inbox');
        $this->oTemp->parse('main.value');

        $this->oTemp->assign('toobar_new', '?sMod=message&sAction=do_add_form');
        $this->oTemp->parse('main.toobar_new');
        $this->oTemp->assign('toobar_save',"formSubmit('frmUpdate')");
        $this->oTemp->parse('main.toobar_save');
    }

    public function displayMessageOutbox($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/message_board_outbox.html');
        $this->oTemp->assign('pageHeding', $oModel->aLanguage[MODULE_HEADING]['Message']);
        $this->oTemp->assign('pageHeding', 'Outbox');

        $this->oTemp->assign_file('temp_filter', PATH_TEMPLATE_ADMIN .'html/message_filter_calendar.html');
        $this->oTemp->assign_file('temp_message_js', PATH_TEMPLATE_ADMIN .'html/message_board_js.html');
        $this->oTemp->assign_file('temp_poup', PATH_TEMPLATE_ADMIN .'html/message_board_popup.html');

        $this->displayCalendarDefault($oModel);
        $this->oTemp->assign('value','outbox');
        $this->oTemp->parse('main.value');

        $this->oTemp->assign('toobar_new', '?sMod=message&sAction=do_add_form');
        $this->oTemp->parse('main.toobar_new');
    }

    public function displayMessageBoard($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/message_board_index.html');
        $this->oTemp->assign('pageHeding', 'Message Board');

        $this->oTemp->assign_file('temp_filter', PATH_TEMPLATE_ADMIN .'html/message_filter_calendar.html');

        $this->oTemp->assign_file('temp_message_js', PATH_TEMPLATE_ADMIN .'html/message_board_js.html');
        $this->oTemp->assign_file('temp_poup', PATH_TEMPLATE_ADMIN .'html/message_board_popup.html');

        $this->oTemp->assign('value','message_board');
        $datenow = date('Y-m-d');
		if($oModel->getData('fromDate') == '')
			$fromDate = $datenow;
		else
			$fromDate = $oModel->getData('toDate');
		if($oModel->getData('toDate') == '')
			$toDate = $datenow;
		else
			$toDate = $oModel->getData('toDate');
        $this->oTemp->assign('fromDate',$fromDate);
        $this->oTemp->assign('toDate',$toDate);

    }

    public function displayMessageNew($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/message_board_new.html');
        $this->oTemp->assign('pageHeding', $oModel->aLanguage[MODULE_HEADING]['Message']);

        $this->oTemp->assign_file('temp_editor', PATH_TEMPLATE_ADMIN .'html/temp_editor_basic.html');

        $this->oTemp->assign('toobar_send',"check_form()");
        $this->oTemp->parse('main.toobar_send');
        $this->oTemp->assign('toobar_cancel', '?sMod=message&sAction=inbox');
        $this->oTemp->parse('main.toobar_cancel');
    }

    public function displayMessageView($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/message_board_view.html');

        $this->oTemp->assign('pageHeding', 'View Message');
        $id=$_REQUEST['id'];
        $rs=$oModel->getInfoOutBoxMessage($id);
        if(is_array($rs)) {
            $this->assignExtract($rs);
            $user_to=$oModel->getInfoUserById($rs['message_to']);
            $this->assignExtract($user_to);
            $this->oTemp->parse('main.row');
        }
        return $this->oTemp->text('main.row');

    }



    public function displayCalendarDefault($oModel) {
        $datenow = date('Y/m/d');
        $tnow = strtotime(date('Y-m-d'));
        $t30 = $tnow-2592000;
        $date30=date('Y/m/d',$t30);
		
		if($oModel->getData('fromDate') == '')
			$fromDate = $date30;
		else
			$fromDate = str_replace('/','-',$oModel->getData('toDate'));
			
		if($oModel->getData('toDate') == '')
			$toDate = $datenow;
		else
			$toDate = str_replace('/','-',$oModel->getData('toDate'));		
		$this->oTemp->assign('fromDate', $fromDate);
        $this->oTemp->assign('toDate', $toDate);
    }

    public function displayListUser($oModel) {
        $rs=$oModel->getListUser();
        if(is_array($rs)) {
            foreach($rs as $row) {
                $this->oTemp->assign('rowUser',$row);
                $this->oTemp->parse('main.rowUser');
            }
        }
    }

    public function displayListMessageOutbox($oModel) {
        $rs=$oModel->getMessageOutBox();
        if(is_array($rs)) {
            $i = 0;
            foreach($rs as $row) {
                $i++;
                $row['no'] = $i;
                $row['css'] = "row" . ($i % 2);
                $row['message_date']=formatDateTimeToScreen($row['message_date']);
                $this->oTemp->assign('rowMessage',$row);
                $this->oTemp->parse('main.rowMessage');
            }
        }
        $this->oTemp->assign("sortByTo",$oModel->oNavigator->setSortField ('amb.message_to',  $oModel->aLanguage['MESSAGE']['to']));
        $this->oTemp->assign("sortByDate",$oModel->oNavigator->setSortField ('amb.message_date',  $oModel->aLanguage['MESSAGE']['date']));
        $this->oTemp->assign('navigator', $oModel->oNavigator->navigator());
    }

    public function displayListMessageInbox($oModel) {
        $rs=$oModel->getMessageInbox();
        if(is_array($rs)) {
            $i = 0;
            foreach($rs as $row) {
                $i++;
                $row['no'] = $i;
                $row['css'] = "row" . ($i % 2);
                $row['message_date']=formatDateTimeToScreen($row['message_date']);
                if($row['message_status']==1) {
                    $row['message_status']="checked";
                }
                $this->oTemp->assign('rowMessage',$row);
                $this->oTemp->parse('main.rowMessage');
            }
        }
        $this->oTemp->assign("sortByFrom",$oModel->oNavigator->setSortField ('amb.message_from', $oModel->aLanguage['MESSAGE']['from']));
        $this->oTemp->assign("sortByDate",$oModel->oNavigator->setSortField ('amb.message_date', $oModel->aLanguage['MESSAGE']['date']));
        $this->oTemp->assign('navigator', $oModel->oNavigator->navigator());
    }

    public function displayInfoOutbox($oModel) {
        $id=$_REQUEST['id'];
        $rs=$oModel->getInfoOutBoxMessage($id);
        if(is_array($rs)) {
            $this->assignExtract($rs);
            $user_to=$oModel->getInfoUserById($rs['message_to']);
            $this->assignExtract($user_to);
            $this->oTemp->parse('main.row');
        }
        return $this->oTemp->text('main.row');
    }

    public function resultXML($oModel, $cCMD, $cResult) {
        $oJSON = new Services_JSON();
        echo $oJSON->encode(array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m:s'), ),
        'BODY' => array('RES' => $cResult)));
    }

    /**
     * MESSAGE BOARD
     */
    public function displayListMessageBoard($oModel) {
        $rs=$oModel->getListMessageBoard();
        if(is_array($rs)) {
            $i = 0;
            foreach($rs as $row) {
                $i++;
                $row['no'] = $i;
                $row['css'] = "row" . ($i % 2);
                $row['message_date']=formatDateTimeToScreen($row['message_date']);

                $user_to=$oModel->getInfoUserById($row['message_to']);
                $row['display_message_to']=$user_to['user_to'];

                $this->oTemp->assign('rowMessage',$row);
                $this->oTemp->parse('main.rowMessage');
            }
        }
        $this->oTemp->assign("sortByTo",$oModel->oNavigator->setSortField('amb.message_to', $oModel->aLanguage['MESSAGE']['to']));
        $this->oTemp->assign("sortByFrom",$oModel->oNavigator->setSortField('amb.message_from', $oModel->aLanguage['MESSAGE']['from']));
        $this->oTemp->assign("sortByDate",$oModel->oNavigator->setSortField('amb.message_date', $oModel->aLanguage['MESSAGE']['date']));
        $this->oTemp->assign('navigator', $oModel->oNavigator->navigator());
    }
}
?>
    